<?php
// +----------------------------------------------------------------------
// | Created by PHPstorm: [ JRK丶Admin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/8/13 0013
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------

namespace app\admin\controller\example;


use app\admin\model\AuthRule;
use app\common\controller\AdminBaseController;
use FormBuilder\Json;
use Jrk\Tool;
use Jrk\Tree;
use think\facade\Db;
use app\common\service\FormBuilder as Form;
use think\facade\Route;


class FormBuilder extends AdminBaseController
{
    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
    }


    public function index()
    {
        $f = [];
        $f[] = Form::input('order_id', '订单编号', "1212")->disabled(1);
        $f[] = Form::number('total_price', '商品总价', '55')->min(0)->col(12);

        $f[] = Form::number('pay_postage', '实际支付邮费', '12.8')->min(0)->precision(2)->col(12);
        $f[] = Form::hidden("id", "123");

        $f[] = Form::frameFileOne("files", "单附件：", Route::buildUrl('admin/AttachMents/getFilesOne', array('fodder' => 'files')))->height("500px")->width('60%')->spin(0)->required("tian")->info("单个附件选择");
        $f[] = Form::frameFiles("filess", "多附件：", Route::buildUrl('admin/AttachMents/getFilesMany', array('fodder' => 'filess')))->height("500px")->width('60%')->spin(0)->required("tia")->maxLength(3)->info("最多只能选择3个附件");

        $f[] = Form::radio('type', '状态', 1)->options([['label' => '直接退款', 'value' => 1], ['label' => '退款后,返回原状态', 'value' => 2]])->vertical(true);

        $f[] = Form::radio('type4', '状态4', 2)->options([['label' => '直接退款', 'value' => 1], ['label' => '退款后,返回原状态', 'value' => 2]]);

        $f[] = Form::input('refund_reason', '退款原因')->type('textarea')->info('退款原因');

        $f[] = Form::frameImageOne("avatar", "单选图片：", Route::buildUrl('admin/AttachMents/getImagesOne', array('fodder' => 'avatar')))->icon('image')->height("500px")->width('60%')->spin(0)->required("ok");
        $f[] = Form::frameImages('image', '多选图片', Route::buildUrl('admin/AttachMents/getImagesMany', array('fodder' => 'image')))->icon('image')->width('90%')->height('500px')->maxLength(3)->required('tian')->info("最多选择三个图片");

        $f[] = Form::input('merger_name', '合并名称', '')->placeholder('格式:陕西,西安,雁塔');

        $f[] = Form::text('order_idd', '退款单号', '1212')->readonly(true);
        $f[] = Form::textarea('refund_reasons', '退款原因2')->rows(5)->info('退款原因2');
        $f[] = Form::select('roles', '管理员身份', "0")->setOptions(function () {
            $list = ["123", "123dsadas", "1dasdasd23", "1fsdfsdfsdf23", "1ghfghfgh23"];
            $options = [];
            foreach ($list as $id => $roleName) {
                $options[] = ['label' => $roleName, 'value' => $id];
            }
            return $options;
        })->multiple(false);
        $f[] = Form::select('rolesd', '多选下拉', "0")->setOptions(function () {
            $list = ["123", "123dsadas", "1dasdasd23", "1fsdfsdfsdf23", "1ghfghfgh23"];
            $options = [];
            foreach ($list as $id => $roleName) {
                $options[] = ['label' => $roleName, 'value' => $id];
            }
            return $options;
        })->multiple(true);

        /* $f[]=Form::dateRange('limit_times', 'dateRange',
             strtotime('- 10 day'),
             time()
         );*/
        $res = AuthRule::menuALL(["status" => 1, 'auth_open' => 1]);
        $list = $this->eachData($res);

       // dd($data);

        $f[] = Form::frameInputOne('icon', '图标', Route::buildUrl('Temp/icon', array('fodder' => 'icon')))->icon('ionic')->height('300px');

        $f[] = Form::frame('co', '内容uedtor', Route::buildUrl('Temp/ueditor', array('fodder' => 'co','id'=>1)),'123456')->icon('ionic')->width("90%")->height('550px');

        $f[]=Form::treeChecked('tree','权限',['11'])->data(
            [
            Form::treeData(11,'leaf 1-1-1')->children([Form::treeData(13,'131313'),Form::treeData(14,'141414')]),
            Form::treeData(12,'leaf 1-1-2')
           ]
        )->col(24);

        $f[] = Form::frame('editormd', 'editormd', Route::buildUrl('Temp/editormd', array('fodder' => 'editormd','id'=>2)),'123456')->icon('ionic')->width("90%")->height('600px');

        $d=treeCheckedtree($list);

        $f[]=Form::treeChecked('treed','权限22',[1,2])->data($d)->col(24);

        $f[] = Form::city('address2', '省市二级联动', '陕西省', '西安市');

        $f[] = Form::cityArea('address', '省市区三级联动', "湖南省", '邵阳市', "邵东县")->filterable(true)->clearable(true);

        $f[] = Form::switches("switches", "switches", '0');
        $f[] = Form::dateTime('add_time', 'dateTime');
        $f[] = Form::color('color', 'color', '#ff0000');
        $f[] = Form::color('color4', 'color4')->format("rgb")->alpha(true);

        $f[] = Form::uploadImageOne('img', '单图片上传', Route::buildUrl('common/uploadImages'))->name('file')->maxSize(10*1024);
        $f[] = Form::uploadImages('imgs', "多图片上传", Route::buildUrl('common/uploadImages'))->name("file")->maxSize(1024*10)->maxLength(2)->info("最多上传2个");

        $f[] = Form::dateTimeRange('dateTimeRange', '区间时间段');
        $f[] = Form::date('riqi', 'date', '2018-03-1');
        $f[] = Form::checkbox('checkbox', 'checkbox', [1])->options([['value' => 1, 'label' => '白色'], ['value' => 2, 'label' => '红色'], ['value' => 31, 'label' => '黑色']]);
        $f[] = Form::rate('month9', '评分等级', 2)->showText(true);
        $f[] = Form::slider('month13', 'slider', 2)->showInput(true)->min(0)->max(25);
        $f[] = Form::sliderRange('month23', 'sliderRange', 2, 13);
        $f[] = Form::time('month16', '时间');
        $f[] = Form::timeRange('month17', '区间时间段');
        $f[] = Form::frameInputs('month18', '多选文件', Route::buildUrl('admin/AttachMents/getFilesMany', array('fodder' => 'month18')))->width("60%")->height("500px")->info("多选文件以文件形式展现");
        $f[] = Form::input('info', '配置名称')->autofocus(true)->required('bitian')->clearable(true);
        $f[] = Form::year('year', 'year');
        $f[] = Form::month('month', 'month');

        $f[] = Form::uploadFileOne('file', '单文件上传', Route::buildUrl('common/uploadFiles'))->name('file')->maxSize(20*1024);
        $f[] = Form::uploadFiles('filed', "多文件上传", Route::buildUrl('common/uploadFiles'))->name("file")->maxSize(1024*20)->maxLength(2)->info("最多上传2个");

        $form = Form::make_post_form('修改订单', $f, Route::buildUrl('update', array("id" => 99)));
        $this->assign(compact('form'));
        return $this->fetch();
    }





    /**
     * @param $list
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @describe: 循环数组追加查看
     */
    protected function eachData($list)
    {
        if (empty($list)) return [];
        foreach ($list as $k => $v) {
            $ck = $this->isChild($v['id']);
            if ($v['type'] == 1 && $ck) {
                array_push($list, ["id" => (int)Tool::uniqidNumberCode(4), "id_" => $v['id'], "pid" => $v['id'], "name" => $v['name'], 'type' => 2, 'title' => '查看', 'auth_open' => 1, 'status' => 1]);
            }
            $list[$k]['id_'] = $v['id'];
        }
        return $list;
    }

    /**
     * @param $id
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @describe:
     */
    protected function isChild($id)
    {
        $res = Db::name("auth_rule")->where("pid", $id)->where("type", 1)->find();
        if ($res) {
            return false;
        }
        return true;
    }

}